<template>
  <div class="container">
    企业名称：    
    <el-input class="com-input" placeholder="请输入内容" v-model="comRecheckParams.name"></el-input>
    修改人：
    <el-select v-model="comRecheckParams.operatorId" placeholder="全部">
      <el-option
        v-for="item in users"
        :key="item.id"
        :label="item.name"
        :value="item.id"
      ></el-option>
    </el-select>
    状态：
    <el-select v-model="comRecheckParams.status" placeholder="全部">
      <el-option
        v-for="item in checkStatus"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      ></el-option>
    </el-select>
    <el-button type="primary" icon="el-icon-search" class="btn" @click="search">查询</el-button>
    <el-main>
      <el-table :data="comInfoList">
        <el-table-column prop="id" align="center" label="ID"></el-table-column>
        <el-table-column prop="name" align="center" label="企业名字"></el-table-column>
        <el-table-column prop="address" align="center" label="企业地址"></el-table-column>
        <el-table-column prop="operatorName" align="center" label="修改人"></el-table-column>
        <el-table-column prop="updateTimeValue" align="center" label="修改时间" width="200"></el-table-column>
        <el-table-column prop="reason" align="center" label="修改原因"></el-table-column>
        <el-table-column prop="statusValue" align="center" label="状态"></el-table-column>
        <el-table-column label="操作" align="center" width="220">
          <template slot-scope="scope">
            <el-button @click="checkDetail(scope.row)" type="text" size="small">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="demonstration-box">
        <!-- <span class="demonstration">显示总数</span> -->
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageParams.size"
          layout="total, prev, pager, next"
          :total="pageParams.totalCount"
        ></el-pagination>
      </div>
    </el-main>
  </div>
</template>

<script>
const queryString = require('querystring')
import page from 'data/page'
import { getUsers } from 'data/listBody'
import { checkStatus, comRecheckParams } from 'data/recheck'
export default {
    name: 'comList',
    mixins: [page],
    data() {
        return {
          checkStatus,
          comRecheckParams,
          // currentPage: this.$router.query.currentPage || 1,
          currentPage: 1,
          totalPage: 0,
          totalCount: 0,
          pageSize: 20,
          pageShow: false,
          users:[],
          comInfoList: []
        }
    },
    props: {
      status: {
        default: false,
        type: Boolean
      }
    },
    created() {
      this.dataInit();
      this.search()
    },
    methods: {
        dataInit(){
          getUsers((res)=>{
            this.users = res;
          })
        },
        search() {
          this.comRecheckParams.page = this.currentPage - 1
          this.axios.get('/company/tempList?' + queryString.stringify(this.comRecheckParams)).then((res) => {
              const code = Number(res.data.code)
              const data = res.data.data
              if (code === 200) {
                  this.comInfoList = data.list
                  this.comInfoList.forEach((comInfo, index) => {
                    this.comInfoList[index].updateTimeValue = this.timeFormater(comInfo.updateTime).format('YYYY-MM-DD')
                    this.comInfoList[index].statusValue = this.getStatusValue(String(comInfo.status))
                  })
                  this.setPage(data)
              } else {
                  this.$message(this.mes.busy)
              }
            }).catch((err) => {
              console.log(err)
              this.$message(this.mes.busy)
            })
        },
        checkDetail(item) {
          this.$router.push('comInfo?id=' + item.id + '&currentPage=' + this.currentPage)
        },
        getStatusValue(val) {
          let value = ''
          switch (val) {
            case '-1': value = '待审核'; break;
            case '0': value = '已审核'; break;
            case '-2': value = '已拒绝'; break;
          }
          return value
        }
    },
    watch: {
      status(val) {
        if (val) this.search()
      }
    }
}
</script>

<style lang="less" scoped>
@import url('../../../../assets/less/checklist.less');
</style>
